<?php
namespace app\admin\logic;
use app\admin\validate\WorkRecordCloud as WorkRecordCloudValidate;

class WorkRecordCloudLogic extends BaseLogic {

    /**
     * 获取工作云盘查询条件
     * @param $parentid
     * @param $keywords
     * @return array
     */
    public function get_search_wrc_maps($parentid,$keywords){
        $maps = [];

        $maps[] = ['parentid','=',$parentid];
        if(!empty($keywords)){
            $maps[] = ['name','like','%' . $keywords . '%'];
        }
        return $maps;
    }

    /**
     * 检查新增文件规则
     * @param $params
     * @return mixed
     */
    public function check_add_file_rule($params){
        $validate = new WorkRecordCloudValidate();
        $r = $validate->scene('add_file')->check($params);
        if(!$r){
            return $this->get_response(0,$validate->getError());
        }
        return $this->get_response(1,'OK');
    }

    /**
     * 检查新增文件夹规则
     * @param $params
     * @return mixed
     */
    public function check_add_foler_rule($params){
        $validate = new WorkRecordCloudValidate();
        $r = $validate->scene('add_folder')->check($params);
        if(!$r){
            return $this->get_response(0,$validate->getError());
        }
        return $this->get_response(1,'OK');
    }

    /**
     * 检查修改文件夹规则
     * @param $params
     * @return mixed
     */
    public function check_save_folder_rule($params){
        $validate = new WorkRecordCloudValidate();
        $r = $validate->scene('edit_folder')->check($params);
        if(!$r){
            return $this->get_response(0,$validate->getError());
        }

        $maps = [];
        $maps[] = ['id','=',$params['wrcid']];
        $wrc_detail = model('work_record_cloud')->get_detail($maps,'id');
        if(empty($wrc_detail)){
            return $this->get_response(0,'该文件不存在');
        }

        $data['wrc_detail'] = $wrc_detail;
        return $this->get_response(1,'OK',$data);
    }
}